﻿using System;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using AxMSTSCLib;

namespace IPv6RemoteTool
{
    public partial class MainWindow : Window
    {
        private AxMsRdpClient9NotSafeForScripting rdpClient;

        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            rdpClient = new AxMsRdpClient9NotSafeForScripting();
            wfHost.Child = rdpClient;
        }

        protected override void OnClosed(EventArgs e)
        {
            if (rdpClient.Connected != 0)
            {
                rdpClient.Disconnect();
            }
            base.OnClosed(e);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
            rdpClient.Server = remoteip.Text;
            rdpClient.UserName = remoteuser.Text;
            rdpClient.AdvancedSettings8.ClearTextPassword = password.Text; // 确保安全处理密码
            rdpClient.Connect();
        }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("连接失败");
                System.Windows.MessageBox.Show("远程功能失败!");
            }
        }
    }
}
